package com.kellycheung.chicken_go_go;

import java.util.LinkedList;

import org.json.JSONObject;

import android.graphics.Color;

import com.kellycheung.chicken_go_go.BaseObject.GOAnchor;
import com.kellycheung.chicken_go_go.GMediaPlayer.GMPType;

public class GameHome extends GameScene {
	public enum StagSelectStatus {
		Selecting, ServerSelecting, ServerReady, ClientReady, AllReady
	}
	
	protected static final int I_EXTRA_CNT = 132; 
	
	protected BaseObject[] boPauseMenuBtn;
	
	protected float fLeftMenuWidth;
	
	protected GMenu gmLeftMenu;
	protected GMenu gmHomeMenu;
	protected GMenu gmExitMenu;
	
	protected GMenu gmFeedMenu;
	protected GMenu gmRaceMenu;
	protected GMenu gmShopMenu;
	protected GMenu gmShopItemMenu;
	protected GMenu gmTutorMenu;
	protected GMenu gmSettingMenu;
	protected GMenu gmCreditMenu;
	protected GMenu gmSoundControlMenu;
	protected GMenu gmShopConfirmMenu;
	protected GMenu gmShopBuyErrMenu;
	protected GMenu gmRaceStageMenu;
	protected GMenu gmRaceStageMenu2;
	protected GMenu gmFeedConfirmMenu;
	protected GMenu gmFeedGoShopMenu;
	protected GMenu gmMultiWaitMenu;
	protected GMenu gmMultiServerWaitMenu;
	protected GMenu gmMultiClientWaitMenu;
	protected TextObject toTitle;
	protected TextObject toGoldNum;
	protected TextObject toTokenNum;
	protected TextObject toItemNum;
	protected TextObject toHappyLv;
	
	/*protected int currentHappyLv;
	protected int currentItemOneQty;
	protected int currentItemTwoQty;
	protected int currentItemQty;
	protected int currentGoldNum;
	protected int currentTokenNum;*/
	protected String currentItemStr;
	//protected int currentRaceStage;
	protected int maxAllowItemNum = 20;
	
	protected PlayerStatusObj statusBarBg;
	protected PlayerStatusObj statusBarEffect;
	protected GPerferences gpMenu;
	protected GameObject goShopItemView;
	protected GameObject goShopItemSelected;
	protected GameObject gpShopBuyErrMsg;
	protected ClickableObj btnBgSoundMuted;
	protected ClickableObj btnEffectSoundMuted;
	protected int buyItem;
	protected int feedItem;
	protected int [][] itemArr = { {10, 10}, {30,25} } ; //happy, price
	protected int buyItemErrCode;
	protected int maxStage = 10;
	protected int raceStageCurrentPage = 1;
	protected int raceStageLineItem = 3;
	protected int raceStageLine= 2;
	protected int raceStagePageTotal = (int)Math.ceil((float)this.maxStage/(raceStageLineItem*raceStageLine));
	protected int raceStageLineTotal = (int)Math.ceil((float)this.maxStage/raceStageLineItem);
	protected TextObject toFeedItemNum;
	protected TextObject toFeedItemNum2;
	protected boolean bIsNetworkMode;
	protected int iGoToStage;
	protected StagSelectStatus sssStatus;
	protected LinkedList<String> sReadyMacAddr;
	
	public GameHome( GameEngine p_geMain , String[] p_sParm ) {
		super( p_geMain , GameHome.I_EXTRA_CNT , p_sParm );
		// TODO Auto-generated constructor stub

		// Background
		GameObject bgGreen = new GameObject( this , 0 , GOAnchor.UpLeft , 0f , 0f );
		bgGreen.addAnimation( new int[]{ R.drawable.bg_green } );
		this.addBackGround( bgGreen );
		this.iLoadCnt++;
		
        this.gpMenu = new GPerferences( p_geMain );
 
		this.geMain.getMenuPerference();
        //this.currentBgSoundLv = this.geMain.currentBgSoundLv;
    	//this.currentEffectSoundLv = this.geMain.currentEffectSoundLv;
    	//this.currentBgSoundMuted = this.geMain.currentBgSoundMuted;
    	//this.currentEffectSoundMuted = this.geMain.currentEffectSoundMuted;

    	
    	/*this.currentHappyLv = this.geMain.currentHappyLv;
    	this.currentItemQty = this.geMain.currentItemQty;
    	this.currentItemOneQty = this.geMain.currentItemOneQty;
    	this.currentItemTwoQty = this.geMain.currentItemTwoQty;
    	this.currentGoldNum = this.geMain.currentGoldNum;
    	this.currentTokenNum = this.geMain.currentTokenNum;
    	this.currentRaceStage = this.geMain.currentRaceStage;*/
    	
		this.initLeftMenu();
		this.initHomeMenu();
		this.initExitMenu();
		this.initFeedMenu();
		this.initFeedConfirmMenu();
        this.initRaceMenu();
        this.initMultiWaitMenu();
        this.initMultiServerWaitMenu();
        this.initMultiClientWaitMenu();
        this.initRaceStageMenu();
        this.initTutorMenu();
        this.initSettingMenu();
        this.initCreditMenu();
        this.initShopMenu();
        this.initShopConfirmMenu();
        this.initShopBuyErrMenu();
        this.initSoundControlMenu();
        this.initFeedGoShopMenu();
        
      //this.gpMenu.removePerference();
      // this.gpMenu.setPerference("gpHappyLv", String.valueOf(100));
     // this.gpMenu.setPerference("gpItemNum", String.valueOf(0));
      //this.gpMenu.setPerference("gpGoldNum", String.valueOf(2));
     // this.gpMenu.setPerference("gpRaceStage", String.valueOf(1));
      //  this.gpMenu.setPerference("gpItemOneQty", String.valueOf(0));
      //  this.gpMenu.setPerference("gpItemTwoQty", String.valueOf(0));
        
       
        this.gssStatus = GameSceneStatus.ghNormal;
        this.gssStatusNormal = GameSceneStatus.ghNormal;
        
        this.sssStatus = StagSelectStatus.Selecting;
        this.bIsNetworkMode = false;
        this.sReadyMacAddr = new LinkedList<String>();
        
        if ( this.sParm != null ) {
        	if ( this.bIsAnyBTConnectionCreated && this.sParm[0].equals( "Again" ) ) {
        		this.gssStatus = GameSceneStatus.ghMultiWait;
        		this.showMultiPlayMenu();
        	}
        }
	}
	
	@Override
	public void initVariables() {
		this.iResBGMusic = 0;
	}
	
	public void initLeftMenu() {
		//Left menu
		this.gmLeftMenu = new GMenu( this , 0f, 0f, this.geMain.gcScreenSize.fX , this.geMain.gcScreenSize.fY , 5 , GameSceneStatus.ghNormal );
		this.iLoadCnt++;
		
		GameObject bgLeftMenu = new GameObject( this , 0 , GOAnchor.UpLeft , 0f , 0f );
		bgLeftMenu.addAnimation( new int[]{ R.drawable.menu_wood } );
        this.gmLeftMenu.addMenuBg( bgLeftMenu );
        this.fLeftMenuWidth = bgLeftMenu.grBound.fRight;
		this.iLoadCnt++;

        //Title bg
  		GameObject bgTitle = new GameObject( this , 0 , GOAnchor.UpLeft , 0f , 0f );
  		bgTitle.addAnimation( new int[]{ R.drawable.menu_black } );
        this.gmLeftMenu.addMenuBg( bgTitle );
  		this.gmLeftMenu.grBound.set( new GRectangle( bgTitle.grBound.fRight , bgTitle.grBound.fDown , 0f , this.geMain.gcScreenSize.fY ).scale( 1f , 0.8f , GOAnchor.Center ) );
		this.iLoadCnt++;

        //Back button
        ClickableObj backBtn = new ClickableObj( this , 0 , GOAnchor.UpLeft , 0f , 0f);
        backBtn.addAnimation( new int[]{ R.drawable.btn_back } );
        backBtn.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				// TODO Auto-generated method stub
				backButtonHandler();
				return null;
			}
        } );
        this.gmLeftMenu.addMenuBg( backBtn );
        backBtn.gssAllowStatus = GameSceneStatus.all;
		this.iLoadCnt++;
        
  		// Title Text
    	toTitle = new TextObject( this , 0 , GOAnchor.Center , (backBtn.grBound.fRight + bgTitle.grBound.getWidth()) / 2 , backBtn.grBound.fUp + backBtn.grBound.getHeight()/2 , "HOME" );
        toTitle.iColor = Color.WHITE;
  		this.gmLeftMenu.addMenuFg( toTitle );
		this.iLoadCnt++;
  		

        this.gmLeftMenu.addNewMenuRow( 1 );
		GameObject bgMoneyLbl = new GameObject( this , 0 , GOAnchor.Center );
		bgMoneyLbl.addAnimation( new int[]{ R.drawable.bg_gold } );
		this.gmLeftMenu.addMenuItem( bgMoneyLbl );
		this.iLoadCnt++;

		// Text Gold num
    	toGoldNum = new TextObject( this , 0 , GOAnchor.Center , bgLeftMenu.getWidth()/2 , bgMoneyLbl.grBound.fUp+(bgMoneyLbl.getHeight()/2) , String.valueOf( this.geMain.gpPref.getPerference( "gpGoldNum" , 0 ) ) );
    	toGoldNum.iColor = Color.WHITE;
  		this.gmLeftMenu.addMenuFg( toGoldNum );
		this.iLoadCnt++;
		
		 this.gmLeftMenu.addNewMenuRow( 1 );
		GameObject bgMoneyBlueLbl = new GameObject( this , 0 , GOAnchor.Center );
		bgMoneyBlueLbl.addAnimation( new int[]{ R.drawable.bg_gold_blue } );
		this.gmLeftMenu.addMenuItem( bgMoneyBlueLbl );
		this.iLoadCnt++;

		// Text Token num
		toTokenNum = new TextObject( this , 0 , GOAnchor.Center , bgLeftMenu.getWidth()/2 , bgMoneyBlueLbl.grBound.fUp+(bgMoneyBlueLbl.getHeight()/2) , String.valueOf( this.geMain.gpPref.getPerference( "gpTokenNum" , 0 ) ) );
		toTokenNum.iColor = Color.WHITE;
  		this.gmLeftMenu.addMenuFg( toTokenNum );
		this.iLoadCnt++;
		
			
        this.gmLeftMenu.addNewMenuRow( 1 );
		GameObject bgItemLbl = new GameObject( this , 0 , GOAnchor.Center );
		bgItemLbl.addAnimation( new int[]{ R.drawable.bg_item } );
		this.gmLeftMenu.addMenuItem( bgItemLbl );
		this.iLoadCnt++;
        
		// Title item num
        toItemNum = new TextObject( this , 0 , GOAnchor.Center , bgLeftMenu.getWidth()/2 , bgItemLbl.grBound.fUp+(bgItemLbl.getHeight()/2) , String.valueOf( this.geMain.gpPref.getPerference( "gpItemNum" , 0 ) ) + " / " + String.valueOf( this.geMain.gpPref.getPerference( "gpItemMax" , 20 ) ) );
    	toItemNum.iColor = Color.WHITE;
  		this.gmLeftMenu.addMenuFg( toItemNum );
		this.iLoadCnt++;
		
        this.gmLeftMenu.addNewMenuRow( 1 );
		GameObject bgHappyLbl = new GameObject( this , 0 , GOAnchor.Center );
		bgHappyLbl.addAnimation( new int[]{ R.drawable.bg_happy } );
		this.gmLeftMenu.addMenuItem( bgHappyLbl );
		this.iLoadCnt++;
		
		// Title Happy Lv
        toHappyLv = new TextObject( this , 0 , GOAnchor.Center , bgLeftMenu.getWidth()/2 , bgHappyLbl.grBound.fUp+(bgHappyLbl.getHeight()/2) , String.valueOf( this.geMain.gpPref.getPerference( "gpHappyLv" , 0 ) ) + "%" );
    	toHappyLv.iColor = Color.WHITE;
  		this.gmLeftMenu.addMenuFg( toHappyLv );
		this.iLoadCnt++;
		
		 this.gmLeftMenu.addNewMenuRow( 1 );
		this.gmLeftMenu.addMenuItem( null );
		this.iLoadCnt++;
			
        this.gmLeftMenu.isShowing = true;
        
        this.algmMenuList.add( this.gmLeftMenu );
		this.iLoadCnt++;
		
		this.iGoToStage = 0;
	}
	
	public void initHomeMenu() {
		//Home menu
      	this.gmHomeMenu = new GMenu( this , this.fLeftMenuWidth, 0f, this.geMain.gcScreenSize.fX-this.fLeftMenuWidth , this.geMain.gcScreenSize.fY , 2 , GameSceneStatus.ghNormal );
      	this.gmHomeMenu.grBound.set( this.gmHomeMenu.grBound.scale( 0.9f , 0.9f , GOAnchor.Center  ) );
		this.iLoadCnt++;
      	
        this.gmHomeMenu.addNewMenuRow( 2 );
      	ClickableObj houseFeed = new ClickableObj( this , 0 , GOAnchor.Center );
      	houseFeed.addAnimation( new int[]{ R.drawable.house_feed } );
      	houseFeed.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				showFeedMenu();
				return null;
			}
		});
		this.gmHomeMenu.addMenuItem( houseFeed );
		this.iLoadCnt++;
		
		ClickableObj houseRace = new ClickableObj( this , 0 , GOAnchor.Center );
		houseRace.sObjName = "House Race";
		houseRace.addAnimation( new int[]{ R.drawable.house_race } );
		houseRace.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				showRaceMenu();
				return null;
			}
		});
		this.gmHomeMenu.addMenuItem( houseRace );
		this.iLoadCnt++;
		
        this.gmHomeMenu.addNewMenuRow( 2 );
		ClickableObj houseShop = new ClickableObj( this , 0 , GOAnchor.Center );
		houseShop.addAnimation( new int[]{ R.drawable.house_shop } );
		houseShop.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				showShopMenu();
				return null;
			}
		});
		this.gmHomeMenu.addMenuItem( houseShop );
		this.iLoadCnt++;
		
		ClickableObj houseAbout = new ClickableObj( this , 0 , GOAnchor.Center );
		houseAbout.addAnimation( new int[]{ R.drawable.house_about } );
		houseAbout.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				showSettingMenu();
				return null;
			}
		});
		this.gmHomeMenu.addMenuItem( houseAbout );
		this.iLoadCnt++;
		
		
		this.gmHomeMenu.isShowing = true;
		
	    this.algmMenuList.add( this.gmHomeMenu );
	    
	    this.gmNowShowing = this.gmHomeMenu;
	    
		this.iLoadCnt++;
	}

	public void initRaceStageMenu() {
		//Race menu
      	this.gmRaceStageMenu = new GMenu( this , this.fLeftMenuWidth, 0f, this.geMain.gcScreenSize.fX-this.fLeftMenuWidth , this.geMain.gcScreenSize.fY/3*2 , 2 , GameSceneStatus.ghRaceStage );
      	this.gmRaceStageMenu.grBound.set( this.gmRaceStageMenu.grBound.scale( 0.9f , 0.9f , GOAnchor.Center  ) );
		this.gmRaceStageMenu.iPage = 0;
      	this.iLoadCnt++;
      	int count = 0;
		int[] imgArr = {
				R.drawable.stage1
				,R.drawable.stage2
				,R.drawable.stage3
				,R.drawable.stage4
				,R.drawable.stage5
				,R.drawable.stage6
				,R.drawable.stage7
				,R.drawable.stage8
				,R.drawable.stage9
				,R.drawable.stage10
		};
      	
      	for ( int j = 0 ; j < this.raceStageLineTotal ; j++ ) {
      		this.gmRaceStageMenu.addNewMenuRow( 3 );
      		for ( int i = 0; i < this.raceStageLineItem && count < this.maxStage ; i++) {
      			ClickableObj btnStage = new ClickableObj( this , 0 , GOAnchor.Center );
				if ( j * this.raceStageLineItem + i + 1 > this.geMain.gpPref.getPerference( "gpRaceStage" , 1 ) ) {
					btnStage.addAnimation( new int[]{ R.drawable.stage_lock } );
				}
				else {
					btnStage.addAnimation( new int[]{ imgArr[ j* this.raceStageLineItem + i ] } );
				}
				
      			btnStage.setBtnClickAct( new ButtonFunction( new String[] { String.valueOf( j * this.raceStageLineItem + i + 1 ) } ) {
					@Override
					public String[] call() throws Exception {
						//goRacePage( this.getParm() );
						iGoToStage = Integer.valueOf(this.getParm()[0]);
						if ( bIsNetworkMode == false ) {
							sssStatus = StagSelectStatus.AllReady;
						}
						return null;
					}
				} );
				this.gmRaceStageMenu.addMenuItem( btnStage );
				this.iLoadCnt++;
				count++;
			}
      	}
      	
      	this.algmMenuList.add( this.gmRaceStageMenu );
      	
      	
      	this.gmRaceStageMenu2 = new GMenu( this , this.fLeftMenuWidth, this.geMain.gcScreenSize.fY/3*2, this.geMain.gcScreenSize.fX-this.fLeftMenuWidth , this.geMain.gcScreenSize.fY/3 , 1 , GameSceneStatus.ghRaceStage );
      	this.gmRaceStageMenu2.grBound.set( this.gmRaceStageMenu2.grBound.scale( 0.9f , 0.9f , GOAnchor.UpLeft  ) );
      	this.gmRaceStageMenu2.iPage = 0;
      	this.iLoadCnt++;
      	
      	
      	for(int i = 0; i < this.raceStagePageTotal; i++)
      	{
      		this.gmRaceStageMenu2.addNewMenuRow( 2 );
      		if(i == 0 )
          	{
          		this.gmRaceStageMenu2.addMenuItem( null );
          		this.iLoadCnt++;
          		
          		ClickableObj btnRight = new ClickableObj( this , 0 , GOAnchor.Up );
          		btnRight.addAnimation( new int[]{ R.drawable.btn_right } );
    			this.gmRaceStageMenu2.addMenuItem( btnRight );
    			this.iLoadCnt++;
    			
    			btnRight.setBtnClickAct( new ButtonFunction( new String[] { String.valueOf( i + 1 ) } ) {
					@Override
					public String[] call() throws Exception {
						nextRaceStagePage( this.getParm() );
						return null;
					}
				} );
          	}
          	else if( i == raceStagePageTotal-1 )
          	{
          		ClickableObj btnLeft = new ClickableObj( this , 0 , GOAnchor.Up );
          		btnLeft.addAnimation( new int[]{ R.drawable.btn_left } );
    			this.gmRaceStageMenu2.addMenuItem( btnLeft );
    			this.iLoadCnt++;
    			
    			btnLeft.setBtnClickAct( new ButtonFunction( new String[] { String.valueOf( i - 1 ) } ) {
					@Override
					public String[] call() throws Exception {
						previousRaceStagePage( this.getParm() );
						return null;
					}
				} );
    			
    			this.gmRaceStageMenu2.addMenuItem( null );
          		this.iLoadCnt++;
          	}
          	else
          	{
          		ClickableObj btnLeft = new ClickableObj( this , 0 , GOAnchor.Up );
          		btnLeft.addAnimation( new int[]{ R.drawable.btn_left } );
    			this.gmRaceStageMenu2.addMenuItem( btnLeft );
    			this.iLoadCnt++;
        		
          	
    			btnLeft.setBtnClickAct( new ButtonFunction( new String[] { String.valueOf( i - 1 ) } ) {
					@Override
					public String[] call() throws Exception {
						previousRaceStagePage( this.getParm() );
						return null;
					}
				} );
    			
        		ClickableObj btnRight = new ClickableObj( this , 0 , GOAnchor.Up );
          		btnRight.addAnimation( new int[]{ R.drawable.btn_right } );
    			this.gmRaceStageMenu2.addMenuItem( btnRight );
    			this.iLoadCnt++;
    			
    			btnRight.setBtnClickAct( new ButtonFunction( new String[] { String.valueOf( i + 1 ) } ) {
					@Override
					public String[] call() throws Exception {
						previousRaceStagePage( this.getParm() );
						return null;
					}
				} );
          	}
      	}
      	
      	
		this.algmMenuList.add( this.gmRaceStageMenu2 );
		this.iLoadCnt++;
	}
	
	public void initExitMenu() {
		// Exit Menu
		this.gmExitMenu = new GMenu( this , 0f , 0f , this.geMain.gcScreenSize.fX , this.geMain.gcScreenSize.fY , 2 , GameSceneStatus.ghExit );
		this.iLoadCnt++;
		
		GeometryObj goWinAlphaBg = new GeometryObj( this , 0 , GOAnchor.Center , this.geMain.gcScreenSize.fX/2f , this.geMain.gcScreenSize.fY/2f );
		goWinAlphaBg.setGeometry( new GRectangle( this.geMain.gcScreenSize.fX , 0f , 0f , this.geMain.gcScreenSize.fY ) , Color.rgb(255,255,255) , 127 );
		this.gmExitMenu.addMenuBg( goWinAlphaBg );
		this.iLoadCnt++;
		
		GameObject goWinGrey = new GameObject( this , 0 , GOAnchor.Center , this.geMain.gcScreenSize.fX/2f , this.geMain.gcScreenSize.fY/2f );
		goWinGrey.addAnimation( new int[]{ R.drawable.background_grey } );
		this.gmExitMenu.addMenuBg( goWinGrey );
		this.gmExitMenu.grBound.set( goWinGrey.grBound );
		this.iLoadCnt++;
		
		this.gmExitMenu.addNewMenuRow( 1 );
		GameObject goWinYeah = new GameObject( this , 0 , GOAnchor.Center );
		goWinYeah.addAnimation( new int[]{ R.drawable.txt_areyousure_exit } );
		this.gmExitMenu.addMenuItem( goWinYeah );
		this.iLoadCnt++;
		
		this.gmExitMenu.addNewMenuRow( 2 );
		ClickableObj btnNot = new ClickableObj( this , 0 , GOAnchor.Center );
		btnNot.addAnimation( new int[]{ R.drawable.btn_not } );
		this.gmExitMenu.addMenuItem( btnNot );
		btnNot.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				// TODO Auto-generated method stub
				backButtonHandler();
				return null;
			}
		} );
		this.iLoadCnt++;
		
		ClickableObj btnOK = new ClickableObj( this , 0 , GOAnchor.Center );
		btnOK.addAnimation( new int[]{ R.drawable.btn_ok } );
		this.gmExitMenu.addMenuItem( btnOK );
		this.iLoadCnt++;
		
		btnOK.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				// TODO Auto-generated method stub
				//geMain.aApp.finish();
				geMain.isGameEnded = true;
				return null;
			}
		} );
		this.iLoadCnt++;
		
		this.algmMenuList.add( this.gmExitMenu );
		this.iLoadCnt++;
	}
	
	public void initRaceMenu() {
		 //Race menu
      	this.gmRaceMenu = new GMenu( this , this.fLeftMenuWidth, 0f, this.geMain.gcScreenSize.fX-this.fLeftMenuWidth , this.geMain.gcScreenSize.fY , 4 , GameSceneStatus.ghRace );
      	this.gmRaceMenu.grBound.set( this.gmRaceMenu.grBound.scale( 0.9f , 0.9f , GOAnchor.Center  ) );
		this.iLoadCnt++;
      	
      	this.gmRaceMenu.addNewMenuRow( 1 );
		ClickableObj btnRaceSingle = new ClickableObj( this , 0 , GOAnchor.Center );
		btnRaceSingle.sObjName = "Race Single";		
		btnRaceSingle.addAnimation( new int[]{ R.drawable.btn_race_single } );
		btnRaceSingle.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				showRaceStageMenu();
				return null;
			}
		} );
		this.gmRaceMenu.addMenuItem( btnRaceSingle );
		this.iLoadCnt++;
		
		this.gmRaceMenu.addNewMenuRow( 1 );
		ClickableObj btnRaceMulti = new ClickableObj( this , 0 , GOAnchor.Center );
		btnRaceMulti.addAnimation( new int[]{ R.drawable.btn_race_multi } );
		btnRaceMulti.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				showMultiWaitMenu();
				return null;
			}
		} );
		this.gmRaceMenu.addMenuItem( btnRaceMulti );
		this.iLoadCnt++;
		
		this.gmRaceMenu.addNewMenuRow( 1 );
		ClickableObj btnTutorial = new ClickableObj( this , 0 , GOAnchor.Center );
		btnTutorial.addAnimation( new int[]{ R.drawable.btn_tutorial } );
		this.gmRaceMenu.addMenuItem( btnTutorial );
		this.iLoadCnt++;
		
		btnTutorial.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				// TODO Auto-generated method stub
				showTutorMenu();
				return null;
			}
		} );
		this.iLoadCnt++;
		
		this.algmMenuList.add( this.gmRaceMenu );
		this.iLoadCnt++;
	}
	
	public void initMultiWaitMenu() {
		 //Race menu
		this.gmMultiWaitMenu = new GMenu( this , this.fLeftMenuWidth, 0f, this.geMain.gcScreenSize.fX-this.fLeftMenuWidth , this.geMain.gcScreenSize.fY , 1 , GameSceneStatus.ghMultiWait );
   		this.gmMultiWaitMenu.grBound.set( this.gmMultiWaitMenu.grBound.scale( 0.9f , 0.9f , GOAnchor.Center ) );
		this.iLoadCnt++;
   	
		this.gmMultiWaitMenu.addNewMenuRow( 1 );
		TextObject toPleaseWait = new TextObject( this , 0 , GOAnchor.Center , this.gmMultiWaitMenu.grBound.getCenter().fX , this.gmMultiWaitMenu.grBound.getCenter().fY , "Please wait \nor press return key to cancel..." );
		toPleaseWait.iFontSize = 80;
		toPleaseWait.iColor= Color.WHITE;
		this.gmMultiWaitMenu.addMenuItem( toPleaseWait );
		this.iLoadCnt++;
		
		this.algmMenuList.add( this.gmMultiWaitMenu );
		this.iLoadCnt++;
	}
	
	public void initMultiServerWaitMenu() {
		 //Race menu
    	this.gmMultiServerWaitMenu = new GMenu( this , this.fLeftMenuWidth, 0f, this.geMain.gcScreenSize.fX-this.fLeftMenuWidth , this.geMain.gcScreenSize.fY , 2 , GameSceneStatus.ghMultiServerWait );
    	this.gmMultiServerWaitMenu.grBound.set( this.gmMultiServerWaitMenu.grBound.scale( 0.9f , 0.9f , GOAnchor.Center ) );
		this.iLoadCnt++;
    	
		this.gmMultiServerWaitMenu.addNewMenuRow( 1 );
    	TextObject toContMultiRace = new TextObject( this , 0 , GOAnchor.Up , this.geMain.gcScreenSize.fX-this.fLeftMenuWidth , this.geMain.gcScreenSize.fY , "All players has connected?" );
    	toContMultiRace.iFontSize = 80;
    	toContMultiRace.iColor= Color.WHITE;
    	this.gmMultiServerWaitMenu.addMenuItem( toContMultiRace );
		
    	this.gmMultiServerWaitMenu.addNewMenuRow( 2 );
    	ClickableObj coCancel = new ClickableObj( this , 0 , GOAnchor.Down );
		coCancel.addAnimation( new int[]{ R.drawable.btn_not } );
		coCancel.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				showMultiPlayMenu();
				return null;
			}
		} );
		this.gmMultiServerWaitMenu.addMenuItem( coCancel );
		this.iLoadCnt++;
		
    	ClickableObj coOK = new ClickableObj( this , 0 , GOAnchor.Down );
		coOK.addAnimation( new int[]{ R.drawable.btn_ok } );
		coOK.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				showRaceStageMenu();
				return null;
			}
		} );
		this.gmMultiServerWaitMenu.addMenuItem( coOK );
		this.iLoadCnt++;

		this.algmMenuList.add( this.gmMultiServerWaitMenu );
		this.iLoadCnt++;
	}
	
	public void initMultiClientWaitMenu() {
		 //Race menu
    	this.gmMultiClientWaitMenu = new GMenu( this , this.fLeftMenuWidth, 0f, this.geMain.gcScreenSize.fX-this.fLeftMenuWidth , this.geMain.gcScreenSize.fY , 1 , GameSceneStatus.ghMultiClientWait );
    	this.gmMultiClientWaitMenu.grBound.set( this.gmMultiClientWaitMenu.grBound.scale( 0.9f , 0.9f , GOAnchor.Center ) );
		this.iLoadCnt++;
    	
		this.gmMultiClientWaitMenu.addNewMenuRow( 1 );
		TextObject toPleaseWait = new TextObject( this , 0 , GOAnchor.Center , this.gmMultiClientWaitMenu.grBound.getCenter().fX , this.gmMultiClientWaitMenu.grBound.getCenter().fY , "Please wait \nor press return key to cancel..." );
		toPleaseWait.iFontSize = 80;
		toPleaseWait.iColor= Color.WHITE;
		this.gmMultiClientWaitMenu.addMenuItem( toPleaseWait );
		this.iLoadCnt++;
		
		this.algmMenuList.add( this.gmMultiClientWaitMenu );
		this.iLoadCnt++;
	}
	
	public void initSettingMenu() {
		 //Setting menu
     	this.gmSettingMenu = new GMenu( this , this.fLeftMenuWidth, 0f, this.geMain.gcScreenSize.fX-this.fLeftMenuWidth , this.geMain.gcScreenSize.fY , 4 , GameSceneStatus.ghSetting );
     	this.gmSettingMenu.grBound.set( this.gmSettingMenu.grBound.scale( 0.9f , 0.9f , GOAnchor.Center  ) );
		this.iLoadCnt++;
     	
     	this.gmSettingMenu.addNewMenuRow( 1 );
		ClickableObj btnAboutGame = new ClickableObj( this , 0 , GOAnchor.Center );
		btnAboutGame.addAnimation( new int[]{ R.drawable.btn_aboutgame } );
		btnAboutGame.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				showCreditMenu();
				return null;
			}
		} );
		this.gmSettingMenu.addMenuItem( btnAboutGame );
		this.iLoadCnt++;
		
		this.gmSettingMenu.addNewMenuRow( 1 );
		ClickableObj btnSoundControl = new ClickableObj( this , 0 , GOAnchor.Center );
		btnSoundControl.addAnimation( new int[]{ R.drawable.btn_soundcontrol } );
		this.gmSettingMenu.addMenuItem( btnSoundControl );
		this.iLoadCnt++;
		
		btnSoundControl.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				// TODO Auto-generated method stub
				showSoundControlMenu();
				return null;
			}
		} );
		this.iLoadCnt++;
		
		this.algmMenuList.add( this.gmSettingMenu );
		this.iLoadCnt++;
	}
	
	public void initCreditMenu() {
		//Credit menu
      	this.gmCreditMenu = new GMenu( this , this.fLeftMenuWidth, 0f, this.geMain.gcScreenSize.fX-this.fLeftMenuWidth , this.geMain.gcScreenSize.fY , 1 , GameSceneStatus.ghCredit );
      	this.gmCreditMenu.grBound.set( this.gmCreditMenu.grBound.scale( 0.9f , 0.9f , GOAnchor.Center  ) );
		this.iLoadCnt++;
      	
      	this.gmCreditMenu.addNewMenuRow( 1 );
      	GameObject dialogTutor = new GameObject( this , 0 , GOAnchor.Center , this.fLeftMenuWidth+((this.geMain.gcScreenSize.fX-this.fLeftMenuWidth)/2f) , this.geMain.gcScreenSize.fY/2f );
      	dialogTutor.addAnimation( new int[]{ R.drawable.dialog_credit } );
		this.gmCreditMenu.addMenuBg( dialogTutor );
		this.iLoadCnt++;
		
		this.algmMenuList.add( this.gmCreditMenu );
		this.iLoadCnt++;
	}
	
	public void initFeedMenu() {
		//Feed menu
		
		this.gmFeedMenu = new GMenu( this , this.fLeftMenuWidth, 0f, this.geMain.gcScreenSize.fX-this.fLeftMenuWidth , this.geMain.gcScreenSize.fY , 2 , GameSceneStatus.ghFeed );
		this.iLoadCnt++;


      	
      	GameObject goFeedMe = new GameObject( this , 0 , GOAnchor.Up, this.fLeftMenuWidth+((this.geMain.gcScreenSize.fX-this.fLeftMenuWidth)/2), 10f*this.geMain.gcScreenSize.fY/1080 );
      	goFeedMe.addAnimation( new int[]{ R.drawable.txt_feedme } );
		this.gmFeedMenu.addMenuBg( goFeedMe );
		this.iLoadCnt++;

		//this.gmFeedMenu.addNewMenuRow( 1 );
		GameObject goFood = new GameObject( this , 0 , GOAnchor.UpLeft , this.fLeftMenuWidth+50f , goFeedMe.grBound.fDown+(50f*this.geMain.gcScreenSize.fY/1080));
		goFood.addAnimation( new int[]{ R.drawable.crop } );
		this.gmFeedMenu.addMenuBg( goFood );
		this.iLoadCnt++;

		GameObject goRedBg = new GameObject( this , 0 , GOAnchor.Center , goFood.grBound.fRight , goFood.grBound.fDown );
		goRedBg.addAnimation( new int[]{ R.drawable.sound_red } );
		this.gmFeedMenu.addMenuBg( goRedBg );
		this.iLoadCnt++;
		
		toFeedItemNum = new TextObject( this , 0 , GOAnchor.Center , goRedBg.grBound.fLeft+(goRedBg.getWidth()/2) , goRedBg.grBound.fUp+(goRedBg.getHeight()/2) , String.valueOf( this.geMain.gpPref.getPerference( "gpItemOneQty" , 0 ) ) );
		toFeedItemNum.iFontSize = 80;
		toFeedItemNum.iColor= Color.WHITE;
		this.gmFeedMenu.addMenuFg( toFeedItemNum );
		this.iLoadCnt++; 

		
		GameObject goHappy = new GameObject( this , 0 , GOAnchor.Left , goFood.grBound.fRight+30f , goFood.grBound.fUp+ (goFood.getHeight()/2f) );
		goHappy.addAnimation( new int[]{ R.drawable.lbl_heart } );
		this.gmFeedMenu.addMenuBg( goHappy );
		this.iLoadCnt++;
		
		TextObject toAdd = new TextObject( this , 0 , GOAnchor.Center , goHappy.grBound.fLeft+(goHappy.getWidth()/2) ,  goHappy.grBound.fUp+ (goHappy.getHeight()/2f) , "+" );
		toAdd.iColor= Color.WHITE;
		this.gmFeedMenu.addMenuFg( toAdd );
		this.iLoadCnt++;
		
		TextObject toFeedItemHappyLv = new TextObject( this , 0 , GOAnchor.Left , goHappy.grBound.fRight ,  goFood.grBound.fUp+ (goFood.getHeight()/2f) , String.valueOf(itemArr[0][0]) );
  		this.gmFeedMenu.addMenuFg( toFeedItemHappyLv );
		this.iLoadCnt++;
		
		ClickableObj goEatBtn = new ClickableObj( this , 0 , GOAnchor.Right, this.geMain.gcScreenSize.fX-50f, goFood.grBound.fUp+ (goFood.getHeight()/2f) );
		goEatBtn.addAnimation( new int[]{ R.drawable.btn_feed } );
		this.gmFeedMenu.addMenuFg( goEatBtn );
		this.iLoadCnt++;
		
		goEatBtn.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				// TODO Auto-generated method stub
				showFeedConfirmMenu(1);
				return null;
			}
		} );


		
		GameObject goFood2 = new GameObject( this , 0 , GOAnchor.DownLeft , this.fLeftMenuWidth+50f , this.geMain.gcScreenSize.fY - goRedBg.getHeight() -5f  );
		goFood2.addAnimation( new int[]{ R.drawable.crop2 } );
		this.gmFeedMenu.addMenuBg( goFood2 );
		this.iLoadCnt++;

		GameObject goRedBg2 = new GameObject( this , 0 , GOAnchor.Center , goFood2.grBound.fRight , goFood2.grBound.fDown );
		goRedBg2.addAnimation( new int[]{ R.drawable.sound_red } );
		this.gmFeedMenu.addMenuBg( goRedBg2 );
		this.iLoadCnt++;
		
		toFeedItemNum2 = new TextObject( this , 0 , GOAnchor.Center , goRedBg2.grBound.fLeft+(goRedBg2.getWidth()/2) , goRedBg2.grBound.fUp+(goRedBg2.getHeight()/2) , String.valueOf( this.geMain.gpPref.getPerference( "gpItemTwoQty" , 0 ) ) );
		toFeedItemNum2.iFontSize = 80;
		toFeedItemNum2.iColor= Color.WHITE;
		this.gmFeedMenu.addMenuFg( toFeedItemNum2 );
		this.iLoadCnt++; 

		
		GameObject goHappy2 = new GameObject( this , 0 , GOAnchor.Left , goFood2.grBound.fRight+30f , goFood2.grBound.fUp+ (goFood2.getHeight()/2f) );
		goHappy2.addAnimation( new int[]{ R.drawable.lbl_heart } );
		this.gmFeedMenu.addMenuBg( goHappy2 );
		this.iLoadCnt++;
		
		TextObject toAdd2 = new TextObject( this , 0 , GOAnchor.Center , goHappy2.grBound.fLeft+(goHappy2.getWidth()/2) ,  goHappy2.grBound.fUp+ (goHappy2.getHeight()/2f) , "+" );
		toAdd2.iColor= Color.WHITE;
		this.gmFeedMenu.addMenuFg( toAdd2 );
		this.iLoadCnt++;
		
		TextObject toFeedItemHappyLv2 = new TextObject( this , 0 , GOAnchor.Left , goHappy2.grBound.fRight ,  goFood2.grBound.fUp+ (goFood2.getHeight()/2f) , String.valueOf(itemArr[1][0]) );
  		this.gmFeedMenu.addMenuFg( toFeedItemHappyLv2 );
		this.iLoadCnt++;
		
		ClickableObj goEatBtn2 = new ClickableObj( this , 0 , GOAnchor.Right, this.geMain.gcScreenSize.fX-50f, goFood2.grBound.fUp+ (goFood2.getHeight()/2f) );
		goEatBtn2.addAnimation( new int[]{ R.drawable.btn_feed } );
		this.gmFeedMenu.addMenuFg( goEatBtn2 );
		this.iLoadCnt++;

		goEatBtn2.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				// TODO Auto-generated method stub
				showFeedConfirmMenu(2);
				return null;
			}
		} );

		this.algmMenuList.add( this.gmFeedMenu );
		this.iLoadCnt++;
	}
	
	public void initFeedConfirmMenu() {
		// Feed Confirm Menu
		this.gmFeedConfirmMenu = new GMenu( this , 0f , 0f , this.geMain.gcScreenSize.fX , this.geMain.gcScreenSize.fY , 2 , GameSceneStatus.ghFeedConfirm );
		this.iLoadCnt++;
		
		GeometryObj goWinAlphaBg = new GeometryObj( this , 0 , GOAnchor.Center , this.geMain.gcScreenSize.fX/2f , this.geMain.gcScreenSize.fY/2f );
		goWinAlphaBg.setGeometry( new GRectangle( this.geMain.gcScreenSize.fX , 0f , 0f , this.geMain.gcScreenSize.fY ) , Color.rgb(255,255,255) , 127 );
		this.gmFeedConfirmMenu.addMenuBg( goWinAlphaBg );
		this.iLoadCnt++;
		
		GameObject goWinGrey = new GameObject( this , 0 , GOAnchor.Center , this.geMain.gcScreenSize.fX/2f , this.geMain.gcScreenSize.fY/2f );
		goWinGrey.addAnimation( new int[]{ R.drawable.background_grey } );
		this.gmFeedConfirmMenu.addMenuBg( goWinGrey );
		this.gmFeedConfirmMenu.grBound.set( goWinGrey.grBound );
		this.iLoadCnt++;
		
		this.gmFeedConfirmMenu.addNewMenuRow( 1 );
		GameObject goWinYeah = new GameObject( this , 0 , GOAnchor.Center );
		goWinYeah.addAnimation( new int[]{ R.drawable.txt_areyousure_feed } );
		this.gmFeedConfirmMenu.addMenuItem( goWinYeah );
		this.iLoadCnt++;
		
		this.gmFeedConfirmMenu.addNewMenuRow( 2 );
		ClickableObj btnNot = new ClickableObj( this , 0 , GOAnchor.Center );
		btnNot.addAnimation( new int[]{ R.drawable.btn_not } );
		this.gmFeedConfirmMenu.addMenuItem( btnNot );
		btnNot.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				// TODO Auto-generated method stub
				backButtonHandler();
				return null;
			}
		} );
		this.iLoadCnt++;
		
		ClickableObj btnOK = new ClickableObj( this , 0 , GOAnchor.Center );
		btnOK.addAnimation( new int[]{ R.drawable.btn_ok } );
		this.gmFeedConfirmMenu.addMenuItem( btnOK );
		this.iLoadCnt++;
		
		btnOK.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				feedItem();
				showFeedConfirmMenu(0);
				return null;
			}
		} );
		this.iLoadCnt++;
		
		this.algmMenuList.add( this.gmFeedConfirmMenu );
		this.iLoadCnt++;
	}
	
	public void initFeedGoShopMenu() {
		// Feed Confirm Menu
		this.gmFeedGoShopMenu = new GMenu( this , 0f , 0f , this.geMain.gcScreenSize.fX , this.geMain.gcScreenSize.fY , 2 , GameSceneStatus.ghFeedGoShop );
		this.iLoadCnt++;
		
		GeometryObj goWinAlphaBg = new GeometryObj( this , 0 , GOAnchor.Center , this.geMain.gcScreenSize.fX/2f , this.geMain.gcScreenSize.fY/2f );
		goWinAlphaBg.setGeometry( new GRectangle( this.geMain.gcScreenSize.fX , 0f , 0f , this.geMain.gcScreenSize.fY ) , Color.rgb(255,255,255) , 127 );
		this.gmFeedGoShopMenu.addMenuBg( goWinAlphaBg );
		this.iLoadCnt++;
		
		GameObject goWinGrey = new GameObject( this , 0 , GOAnchor.Center , this.geMain.gcScreenSize.fX/2f , this.geMain.gcScreenSize.fY/2f );
		goWinGrey.addAnimation( new int[]{ R.drawable.background_grey } );
		this.gmFeedGoShopMenu.addMenuBg( goWinGrey );
		this.gmFeedGoShopMenu.grBound.set( goWinGrey.grBound );
		this.iLoadCnt++;
		
		this.gmFeedGoShopMenu.addNewMenuRow( 1 );
		GameObject goWinYeah = new GameObject( this , 0 , GOAnchor.Center );
		goWinYeah.addAnimation( new int[]{ R.drawable.txt_goshop } );
		this.gmFeedGoShopMenu.addMenuItem( goWinYeah );
		this.iLoadCnt++;
		
		this.gmFeedGoShopMenu.addNewMenuRow( 2 );
		ClickableObj btnNot = new ClickableObj( this , 0 , GOAnchor.Center );
		btnNot.addAnimation( new int[]{ R.drawable.btn_not } );
		this.gmFeedGoShopMenu.addMenuItem( btnNot );
		btnNot.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				// TODO Auto-generated method stub
				backButtonHandler();
				return null;
			}
		} );
		this.iLoadCnt++;
		
		ClickableObj btnOK = new ClickableObj( this , 0 , GOAnchor.Center );
		btnOK.addAnimation( new int[]{ R.drawable.btn_ok } );
		this.gmFeedGoShopMenu.addMenuItem( btnOK );
		this.iLoadCnt++;
		
		btnOK.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				showShopMenu();
				return null;
			}
		} );
		this.iLoadCnt++;
		
		this.algmMenuList.add( this.gmFeedGoShopMenu );
		this.iLoadCnt++;
	}
	
	public void feedItem() {
		String sKeyName = "";
		TextObject to = null;
		
		switch ( this.feedItem ) {
		case 1:
			sKeyName = "gpItemOneQty";
			to = this.toFeedItemNum;
			break;
			
		case 2:
			sKeyName = "gpItemTwoQty";
			to = this.toFeedItemNum2;
			break;
		}
		
		if ( this.geMain.gpPref.getPerference( sKeyName , 0 ) > 0 ) {
			this.geMain.gpPref.setPerference( sKeyName , this.geMain.gpPref.getPerference( sKeyName , 0 ) - 1 );
			to.sTxt = String.valueOf( this.geMain.gpPref.getPerference( sKeyName , 0 ) );
			
			this.geMain.gpPref.setPerference( "gpItemNum" , this.geMain.gpPref.getPerference( "gpItemNum" , 0 ) - 1 );
			this.toItemNum.sTxt = String.valueOf( this.geMain.gpPref.getPerference( "gpItemNum" , 0 ) ) + " / " + String.valueOf( this.geMain.gpPref.getPerference( "gpItemMax" , 20 ) );
			
			this.geMain.gpPref.setPerference( "gpHappyLv" , ( this.geMain.gpPref.getPerference( "gpHappyLv" , 100 ) + itemArr[this.feedItem-1][0] > 100 ? 100 : this.geMain.gpPref.getPerference( "gpHappyLv" , 100 ) + itemArr[this.feedItem-1][0] ) );
			this.toHappyLv.sTxt = this.geMain.gpPref.getPerference( "gpHappyLv" , 100 ) + "%";
		}
		
		/*int updatedSelectItemQty;
		boolean feed = false;
		if(this.feedItem == 1)
		{
			updatedSelectItemQty = this.currentItemOneQty - 1;
			if(updatedSelectItemQty >= 0)
			{
				this.currentItemOneQty = updatedSelectItemQty;
				this.toFeedItemNum.sTxt = String.valueOf( currentItemOneQty );
				this.gpMenu.setPerference("gpItemOneQty", String.valueOf(currentItemOneQty));
				feed = true;
			}
		}
		else
		{
			updatedSelectItemQty = this.currentItemTwoQty - 1;
			if(updatedSelectItemQty >= 0)
			{
				this.currentItemTwoQty = updatedSelectItemQty;
				this.toFeedItemNum2.sTxt = String.valueOf(currentItemTwoQty);
				this.gpMenu.setPerference("gpItemTwoQty", String.valueOf(currentItemTwoQty));
				feed = true;
			}
		}
		
		if(feed){
		this.currentItemQty = this.currentItemQty - 1;
		this.toItemNum.sTxt  = String.valueOf( (this.currentItemQty) + " / 20" );
		this.gpMenu.setPerference("gpItemNum", String.valueOf(this.currentItemQty));
		}
		
		int updatedHappyLv = this.currentHappyLv + itemArr[this.feedItem-1][1];
		if(updatedHappyLv <= 100)
		{
			this.toHappyLv.sTxt = String.valueOf(updatedHappyLv)+"%";
			this.currentHappyLv = updatedHappyLv;
			this.gpMenu.setPerference("gpHappyLv", String.valueOf(updatedHappyLv));
		}
		else
		{
			this.currentHappyLv = 100;
			this.toHappyLv.sTxt = "100%";
			this.gpMenu.setPerference("gpHappyLv", String.valueOf(100));
		}*/
	}
	
	public void initShopMenu() {
		//Shop menu
      	this.gmShopMenu = new GMenu( this , this.fLeftMenuWidth, 0f, this.geMain.gcScreenSize.fX-this.fLeftMenuWidth , this.geMain.gcScreenSize.fY , 2 , GameSceneStatus.ghShop );
		this.iLoadCnt++;

      	this.gmShopMenu.addNewMenuRow( 2 );
      	
      	GameObject crop = new GameObject( this , 0 , GOAnchor.Center );
      	crop.addAnimation( new int[]{ R.drawable.crop } );
		this.gmShopMenu.addMenuItem( crop );
		this.iLoadCnt++;

		ClickableObj btnBuy = new ClickableObj( this , 0 , GOAnchor.Center );
		btnBuy.addAnimation( new int[]{ R.drawable.btn_buy } );
		this.gmShopMenu.addMenuItem( btnBuy );
		this.iLoadCnt++;
		
		btnBuy.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				// TODO Auto-generated method stub
				showShopConfirmMenu(1);
				return null;
			}
		} );
		
		this.gmShopMenu.addNewMenuRow( 2 );
      	
		GameObject crop2 = new GameObject( this , 0 , GOAnchor.Center );
      	crop2.addAnimation( new int[]{ R.drawable.crop2 } );
		this.gmShopMenu.addMenuItem( crop2 );
		this.iLoadCnt++;
		
		ClickableObj btnBuy2 = new ClickableObj( this , 0 , GOAnchor.Center );
		btnBuy2.addAnimation( new int[]{ R.drawable.btn_buy } );
		this.gmShopMenu.addMenuItem( btnBuy2 );
		this.iLoadCnt++;
		
		btnBuy2.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				// TODO Auto-generated method stub
				showShopConfirmMenu(2);
				return null;
			}
		} );
		
		this.algmMenuList.add( this.gmShopMenu );
		this.iLoadCnt++;
	}
	
	public void initShopConfirmMenu() {
		// Pause Menu
		this.gmShopConfirmMenu = new GMenu( this , 0f , 0f , this.geMain.gcScreenSize.fX , this.geMain.gcScreenSize.fY , 3 , GameSceneStatus.ghShopConfirm );
		this.iLoadCnt++;
		
        GeometryObj goPauseAlphaBg = new GeometryObj( this , 0 , GOAnchor.Center , this.geMain.gcScreenSize.fX/2f , this.geMain.gcScreenSize.fY/2f );
        goPauseAlphaBg.setGeometry( new GRectangle( this.geMain.gcScreenSize.fX , 0f , 0f , this.geMain.gcScreenSize.fY ) , Color.rgb(255,255,255) , 127 );
        this.gmShopConfirmMenu.addMenuBg( goPauseAlphaBg );
        this.iLoadCnt++;
        
		GameObject goPauseGrey = new GameObject( this , 0 , GOAnchor.Center , this.geMain.gcScreenSize.fX/2f , this.geMain.gcScreenSize.fY/2f );
		goPauseGrey.addAnimation( new int[]{ R.drawable.background_grey } );
		this.gmShopConfirmMenu.addMenuBg( goPauseGrey );
		this.gmShopConfirmMenu.grBound.set( goPauseGrey.grBound.scale( 1.0f , 0.8f , GOAnchor.Center ) );
		this.iLoadCnt++;
		
		this.gmShopConfirmMenu.addNewMenuRow( 1 );
		
		GameObject areYouSure_buy = new GameObject( this , 0 , GOAnchor.Down );
		areYouSure_buy.addAnimation( new int[]{ R.drawable.txt_areyousure_buy } );
		this.gmShopConfirmMenu.addMenuItem( areYouSure_buy );
		this.iLoadCnt++;
			

		
		this.gmShopConfirmMenu.addNewMenuRow( 1 );
		
		goShopItemSelected = new GameObject( this , 0 , GOAnchor.Center );
		goShopItemSelected.addAnimation( new int[]{ R.drawable.shop_item_1 } );
		goShopItemSelected.addAnimation( new int[]{ R.drawable.shop_item_2 } );
		goShopItemSelected.setAnimation();
		goShopItemSelected.playAnimation(true);
		
		this.gmShopConfirmMenu.addMenuItem( goShopItemSelected );
		this.iLoadCnt++;
	
		this.gmShopConfirmMenu.addNewMenuRow( 2 );
		
		ClickableObj btn_not = new ClickableObj( this , 0 , GOAnchor.Up );
		btn_not.addAnimation( new int[]{ R.drawable.btn_not } );
		this.gmShopConfirmMenu.addMenuItem( btn_not );
		this.iLoadCnt++;
		
		btn_not.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				// TODO Auto-generated method stub
				showShopConfirmMenu(0);
				return null;
			}
		} );
		
		ClickableObj btn_ok = new ClickableObj( this , 0 , GOAnchor.Up );
		btn_ok.addAnimation( new int[]{ R.drawable.btn_ok } );
		this.gmShopConfirmMenu.addMenuItem( btn_ok );
		this.iLoadCnt++;
		
		btn_ok.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				// TODO Auto-generated method stub
				buyItem();
				showShopConfirmMenu(0);
				return null;
			}
		} );
		
		this.algmMenuList.add( this.gmShopConfirmMenu );
		this.iLoadCnt++;
	}
	
	public void initShopBuyErrMenu() {
		// Pause Menu
		this.gmShopBuyErrMenu = new GMenu( this , 0f , 0f , this.geMain.gcScreenSize.fX , this.geMain.gcScreenSize.fY , 2 , GameSceneStatus.ghShopBuyErr );
		this.iLoadCnt++;
		
        GeometryObj goPauseAlphaBg = new GeometryObj( this , 0 , GOAnchor.Center , this.geMain.gcScreenSize.fX/2f , this.geMain.gcScreenSize.fY/2f );
        goPauseAlphaBg.setGeometry( new GRectangle( this.geMain.gcScreenSize.fX , 0f , 0f , this.geMain.gcScreenSize.fY ) , Color.rgb(255,255,255) , 127 );
        this.gmShopBuyErrMenu.addMenuBg( goPauseAlphaBg );
        this.iLoadCnt++;
        
		GameObject goPauseGrey = new GameObject( this , 0 , GOAnchor.Center , this.geMain.gcScreenSize.fX/2f , this.geMain.gcScreenSize.fY/2f );
		goPauseGrey.addAnimation( new int[]{ R.drawable.background_grey } );
		this.gmShopBuyErrMenu.addMenuBg( goPauseGrey );
		this.gmShopBuyErrMenu.grBound.set( goPauseGrey.grBound.scale( 1.0f , 0.8f , GOAnchor.Center ) );
		this.iLoadCnt++;
		
		this.gmShopBuyErrMenu.addNewMenuRow( 1 );
		gpShopBuyErrMsg = new GameObject( this , 0 , GOAnchor.Center  );
		gpShopBuyErrMsg.addAnimation( new int[]{ R.drawable.err_nomoney } );
		gpShopBuyErrMsg.addAnimation( new int[]{ R.drawable.err_fullitem } );
		gpShopBuyErrMsg.setAnimation();
		gpShopBuyErrMsg.playAnimation(true);
		
		this.gmShopBuyErrMenu.addMenuItem( gpShopBuyErrMsg );
		this.iLoadCnt++;

		
		this.gmShopBuyErrMenu.addNewMenuRow( 1 );
		ClickableObj btn_ok = new ClickableObj( this , 0 , GOAnchor.Up );
		btn_ok.addAnimation( new int[]{ R.drawable.btn_ok } );
		this.gmShopBuyErrMenu.addMenuItem( btn_ok );
		this.iLoadCnt++;
		
		btn_ok.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				// TODO Auto-generated method stub
				showShopBuyErrMenu();
				return null;
			}
		} );
		
		this.algmMenuList.add( this.gmShopBuyErrMenu );
		this.iLoadCnt++;
	}
	
	public void buyItem() {
		if ( this.geMain.gpPref.getPerference( "gpGoldNum" , 0 ) < itemArr[this.buyItem-1][0] ) {
			this.buyItemErrCode = 0;
			showShopBuyErrMenu();
		} else if ( this.geMain.gpPref.getPerference( "gpItemNum" , 0 ) >= this.geMain.gpPref.getPerference( "gpItemMax" , 20 ) ) {
			this.buyItemErrCode = 1;
			showShopBuyErrMenu();
		} else {
			String sKey = "";
			TextObject to = null;
			switch ( this.buyItem ) {
			case 1:
				sKey = "gpItemOneQty";
				to = this.toFeedItemNum;
				break;
			case 2:
				sKey = "gpItemTwoQty";
				to = this.toFeedItemNum2;
				break;
			}
			
			this.geMain.gpPref.setPerference( "gpGoldNum" , this.geMain.gpPref.getPerference( "gpGoldNum" , 0 ) - itemArr[this.buyItem-1][0] );
			this.toGoldNum.sTxt  = String.valueOf( this.geMain.gpPref.getPerference( "gpGoldNum" , 0 ) );
			
			this.geMain.gpPref.setPerference( "gpItemNum" , this.geMain.gpPref.getPerference( "gpItemNum" , 0 ) + 1 );
			this.toItemNum.sTxt = String.valueOf( this.geMain.gpPref.getPerference( "gpItemNum" , 0 ) ) + " / " + String.valueOf( this.geMain.gpPref.getPerference( "gpItemMax" , 20 ) );
			
			this.geMain.gpPref.setPerference( sKey , this.geMain.gpPref.getPerference( sKey , 0 ) + 1 );
			to.sTxt = String.valueOf( this.geMain.gpPref.getPerference( sKey , 0 ) );
		}
		
		/*if( this.currentGoldNum <= 0  || this.currentGoldNum < itemArr[this.buyItem-1][1] || this.currentItemQty >= this.maxAllowItemNum )
		{ 
			if( this.currentItemQty >= this.maxAllowItemNum )
			{
				this.buyItemErrCode = 1;
				
			}
			else
			{
				this.buyItemErrCode = 0;
			}
			showShopBuyErrMenu();
		}
		else
		{
			int updatedGoldNum  =  this.currentGoldNum - itemArr[this.buyItem-1][1];
			int updatedItemQty = 1 + this.currentItemQty;
			
			this.gpMenu.setPerference("gpGoldNum", String.valueOf(	updatedGoldNum  ));
			this.gpMenu.setPerference("gpItemNum", String.valueOf( updatedItemQty ));
			this.currentGoldNum = updatedGoldNum;
			this.currentItemQty = updatedItemQty;
			
			this.toGoldNum.sTxt  = String.valueOf( updatedGoldNum );
			this.toItemNum.sTxt  = String.valueOf( updatedItemQty + " / 20" );
			
			/*if(this.currentItemStr.equals(""))
			{
				this.currentItemStr = this.buyItem + ":1";
			}
			else
			{
				int index = this.currentItemStr.indexOf( this.buyItem+":" );
				if(index == -1)
				{
					this.currentItemStr = this.currentItemStr+","+this.buyItem + ":1";
				}
				else
				{
					String selectedItemNum = this.currentItemStr.substring(index+2, index+3);
					int updatedSelectItemNum = Integer.parseInt(selectedItemNum) + 1;
					this.currentItemStr = this.currentItemStr.replace(this.buyItem+":"+selectedItemNum, this.buyItem+":"+String.valueOf(updatedSelectItemNum));
				}
			}*-/
			
			if(this.buyItem == 1)
			{
				this.currentItemOneQty = this.currentItemOneQty+1;
				this.toFeedItemNum.sTxt = String.valueOf(this.currentItemOneQty);
				this.gpMenu.setPerference("gpItemOneQty", String.valueOf(this.currentItemOneQty));
			}
			else
			{
				this.currentItemTwoQty = this.currentItemTwoQty+1;
				this.toFeedItemNum2.sTxt = String.valueOf(currentItemTwoQty);
				this.gpMenu.setPerference("gpItemTwoQty", String.valueOf(currentItemTwoQty));
			}
			
		}*/
	}
	
	public void initSoundControlMenu() {
		//Sound Control menu
      	this.gmSoundControlMenu = new GMenu( this , this.fLeftMenuWidth, 0f, this.geMain.gcScreenSize.fX-this.fLeftMenuWidth , this.geMain.gcScreenSize.fY , 2 , GameSceneStatus.ghSoundControl );
      	this.gmSoundControlMenu.grBound.set( this.gmCreditMenu.grBound.scale( 0.9f , 0.9f , GOAnchor.UpLeft  ) );
		this.iLoadCnt++;

  		// Text Backgound music
		GameObject goBgMusic = new GameObject( this , 0 , GOAnchor.UpLeft , this.fLeftMenuWidth+(150f* this.geMain.gcScreenSize.fY/1918f) , 150f* this.geMain.gcScreenSize.fY/1080f);
		goBgMusic.addAnimation( new int[]{ R.drawable.txt_bgmusic } );
		this.gmSoundControlMenu.addMenuBg( goBgMusic );
		this.iLoadCnt++;
		
     //this.gmSoundControlMenu.addNewMenuRow( 4 );
      	
      	ClickableObj btnBgSoundMinus = new ClickableObj( this , 0 , GOAnchor.UpLeft , this.fLeftMenuWidth+(150f* this.geMain.gcScreenSize.fY/1918f) ,  goBgMusic.grBound.fDown+(10f*this.geMain.gcScreenSize.fY/1080f));
		btnBgSoundMinus.addAnimation( new int[]{ R.drawable.btn_music_minus } );
		this.gmSoundControlMenu.addMenuBg( btnBgSoundMinus );
		this.iLoadCnt++;
		
		btnBgSoundMinus.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				bgSoundMinus();
				return null;
			}
		} );
  
		GameObject bgSoundBar = new GameObject( this , 0 , GOAnchor.UpLeft , btnBgSoundMinus.grBound.fRight+(50f* this.geMain.gcScreenSize.fY/1918f) ,  goBgMusic.grBound.fDown+(10f*this.geMain.gcScreenSize.fY/1080f));
		bgSoundBar.addAnimation( new int[]{ R.drawable.sound_progress_bar } );
		this.gmSoundControlMenu.addMenuBg( bgSoundBar );
		this.iLoadCnt++;
	
		statusBarBg = new PlayerStatusObj( this, 0, GOAnchor.UpLeft, bgSoundBar.grBound.fLeft+8f, bgSoundBar.grBound.fUp+5f , bgSoundBar.getWidth()-16f, bgSoundBar.getHeight()-10f, bgSoundBar.getHeight()-10f );
		this.statusBarBg.addPlayer( 100 );
		
		if(this.geMain.gmpPlayer.isMute( GMPType.bgMusic ))
		{
			this.statusBarBg.changeColor(  String.valueOf(1), 1);
		}
		else
		{
			this.statusBarBg.changeColor(  String.valueOf(1), 0);
		}

		
		this.gmSoundControlMenu.addMenuBg( this.statusBarBg );
		
		GameUtil.LogMsg(this, "volumn now "+String.valueOf(this.geMain.gmpPlayer.getVolume( GMPType.bgMusic )));
		this.statusBarBg.setPlayerProgress( String.valueOf(1) , this.geMain.gmpPlayer.getVolume( GMPType.bgMusic ) );
		
		btnBgSoundMuted = new ClickableObj( this , 0 , GOAnchor.UpLeft , bgSoundBar.grBound.fRight+50f,  goBgMusic.grBound.fDown+10f );
		btnBgSoundMuted.addAnimation( new int[]{ R.drawable.btn_music_muted } );
		btnBgSoundMuted.addAnimation( new int[]{ R.drawable.btn_music_muted_not } );
		this.gmSoundControlMenu.addMenuBg( btnBgSoundMuted );
		this.iLoadCnt++;
		
		if ( this.geMain.gmpPlayer.isMute( GMPType.bgMusic) ) {
			btnBgSoundMuted.setAnimation(1);
		}
		//btnBgSoundMuted.setAnimation(0);
		
		btnBgSoundMuted.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				bgSoundMuted();
				return null;
			}
		} );
		
		ClickableObj btnBgSoundAdd = new ClickableObj( this , 0 , GOAnchor.UpLeft , btnBgSoundMuted.grBound.fRight+(20f* this.geMain.gcScreenSize.fY/1918f) ,  goBgMusic.grBound.fDown+(10f*this.geMain.gcScreenSize.fY/1080f) );
      	btnBgSoundAdd.addAnimation( new int[]{ R.drawable.btn_music_add } );
		this.gmSoundControlMenu.addMenuBg( btnBgSoundAdd );
		this.iLoadCnt++;
		
		btnBgSoundAdd.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				bgSoundAdd();
				return null;
			}
		} );

		// Text Effect sound
		GameObject goEffectSound = new GameObject( this , 0 , GOAnchor.UpLeft ,this.fLeftMenuWidth+(150f* this.geMain.gcScreenSize.fY/1918f)  , this.geMain.gcScreenSize.fY/2+(80f*this.geMain.gcScreenSize.fY/1080f) );
		goEffectSound.addAnimation( new int[]{ R.drawable.txt_effectsound } );
		this.gmSoundControlMenu.addMenuBg( goEffectSound );
		this.iLoadCnt++;
		
      	this.gmSoundControlMenu.addNewMenuRow( 4 );
		ClickableObj btnEffectSoundMinus = new ClickableObj( this , 0 , GOAnchor.UpLeft , this.fLeftMenuWidth+(150f* this.geMain.gcScreenSize.fY/1918f) ,  goEffectSound.grBound.fDown+(10f*this.geMain.gcScreenSize.fY/1080f));
		btnEffectSoundMinus.addAnimation( new int[]{ R.drawable.btn_music_minus } );
		this.gmSoundControlMenu.addMenuBg( btnEffectSoundMinus );
		this.iLoadCnt++;
		
		btnEffectSoundMinus.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				effectSoundMinus();
				return null;
			}
		} );
		
		GameObject effectSoundBar = new GameObject( this , 0 , GOAnchor.UpLeft , btnEffectSoundMinus.grBound.fRight+(50f* this.geMain.gcScreenSize.fY/1918f) ,  goEffectSound.grBound.fDown+(10f*this.geMain.gcScreenSize.fY/1080f));
		effectSoundBar.addAnimation( new int[]{ R.drawable.sound_progress_bar } );
		this.gmSoundControlMenu.addMenuBg( effectSoundBar );
		this.iLoadCnt++;
		
		statusBarEffect = new PlayerStatusObj( this, 0, GOAnchor.UpLeft, effectSoundBar.grBound.fLeft+8f, effectSoundBar.grBound.fUp+5f , effectSoundBar.getWidth()-16f, effectSoundBar.getHeight()-10f, effectSoundBar.getHeight()-10f );
		this.statusBarEffect.addPlayer( 100 );
		this.gmSoundControlMenu.addMenuBg( this.statusBarEffect );
		this.statusBarEffect.setPlayerProgress( String.valueOf(1) , this.geMain.gmpPlayer.getVolume( GMPType.soundEffect ) );
		
		if(this.geMain.gmpPlayer.isMute( GMPType.soundEffect ))
		{
			this.statusBarEffect.changeColor(  String.valueOf(1), 1);
		}
		else
		{
			this.statusBarEffect.changeColor(  String.valueOf(1), 0);
		}
		
		this.btnEffectSoundMuted = new ClickableObj( this , 0 , GOAnchor.UpLeft , effectSoundBar.grBound.fRight+(50f* this.geMain.gcScreenSize.fY/1918f) ,  goEffectSound.grBound.fDown+(10f*this.geMain.gcScreenSize.fY/1080f));
		this.btnEffectSoundMuted.addAnimation( new int[]{ R.drawable.btn_music_muted } );
		this.btnEffectSoundMuted.addAnimation( new int[]{ R.drawable.btn_music_muted_not } );
		this.gmSoundControlMenu.addMenuBg( this.btnEffectSoundMuted );
		this.iLoadCnt++;
		
		if ( this.geMain.gmpPlayer.isMute( GMPType.soundEffect ) ) {
			this.btnEffectSoundMuted.setAnimation(1);
		}
		
		this.btnEffectSoundMuted.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				effectSoundMuted();
				return null;
			}
		} );
		
		
		ClickableObj btnEffectSoundAdd = new ClickableObj( this , 0 , GOAnchor.UpLeft , btnEffectSoundMuted.grBound.fRight+(20f* this.geMain.gcScreenSize.fY/1918f) ,  goEffectSound.grBound.fDown+(10f*this.geMain.gcScreenSize.fY/1080f));
		btnEffectSoundAdd.addAnimation( new int[]{ R.drawable.btn_music_add } );
		this.gmSoundControlMenu.addMenuBg( btnEffectSoundAdd );
		this.iLoadCnt++;
		
		btnEffectSoundAdd.setBtnClickAct( new ButtonFunction() {
			@Override
			public String[] call() throws Exception {
				effectSoundAdd();
				return null;
			}
		} );
				
		this.algmMenuList.add( this.gmSoundControlMenu );
		this.iLoadCnt++;
	}
	
	public void initTutorMenu() {
		//Tutor menu
      	this.gmTutorMenu = new GMenu( this , this.fLeftMenuWidth, 0f, this.geMain.gcScreenSize.fX-this.fLeftMenuWidth , this.geMain.gcScreenSize.fY , 1 , GameSceneStatus.ghTutor );
      	this.gmTutorMenu.grBound.set( this.gmTutorMenu.grBound.scale( 0.9f , 0.9f , GOAnchor.Center  ) );
		this.iLoadCnt++;
      	
      	this.gmTutorMenu.addNewMenuRow( 1 );
      	GameObject dialogTutor = new GameObject( this , 0 , GOAnchor.Center , this.fLeftMenuWidth+((this.geMain.gcScreenSize.fX-this.fLeftMenuWidth)/2f) , this.geMain.gcScreenSize.fY/2f );
      	dialogTutor.addAnimation( new int[]{ R.drawable.dialog_tutorial } );
		this.gmTutorMenu.addMenuBg( dialogTutor );
		this.iLoadCnt++;
		
		this.algmMenuList.add( this.gmTutorMenu );
		this.iLoadCnt++;
	}
	
	@Override
	public void backButtonHandler() {
		this.toTitle.iFontSize = 80;
		this.toTitle.sTxt = "Home";
		
		switch ( this.gssStatus ) {
		case ghNormal:
			this.showExitMenu();
			break;
		case ghExit:
			this.showExitMenu();
			break;
		case ghCredit:
			this.showCreditMenu();
			break;
		case ghSetting:
			this.showSettingMenu();
			break;
		case ghRace:
			this.showRaceMenu();
			break;
		case ghTutor:
			this.showTutorMenu();
			break;
		case ghSoundControl:
			this.showSoundControlMenu();
			break;
		case ghShop:
			this.showShopMenu();
			break;
		case ghShopConfirm:
			this.showShopConfirmMenu(0);
			break;
		case ghShopBuyErr:
			this.showShopBuyErrMenu();
			break;
		case ghMultiWait:
			this.showMultiWaitMenu();
			break;
		case ghMultiServerWait:
		case ghMultiClientWait:
			this.showMultiPlayMenu();
			break;
		case ghRaceStage:
			this.showRaceStageMenu();
			break;
		case ghFeed:
			this.showFeedMenu();
			break;
		case ghFeedConfirm:
		case ghFeedGoShop:
			this.showFeedConfirmMenu(0);
			break;
		default:
			break;
		}
	}
	
	
	public void goRacePage( String[] p_sStage ) {
		if ( Integer.parseInt(p_sStage[0]) <= this.geMain.gpPref.getPerference( "gpRaceStage" , 0 ) ) {
			synchronized ( this.geMain.shMain ) {
				this.geMain.addToNextScene( new GameRacing( this.geMain , p_sStage ) );
			}
		}
		else {
			this.sssStatus = StagSelectStatus.Selecting;
			this.iGoToStage = 0;
		}
	}
	
	public void nextRaceStagePage( String[] p_sStage ) {
		this.gmRaceStageMenu.iPage = Integer.valueOf( p_sStage[0] ); 
		this.gmRaceStageMenu2.iPage = Integer.valueOf( p_sStage[0] ); 
	}
	
	public void previousRaceStagePage( String[] p_sStage ) {
		this.gmRaceStageMenu.iPage = Integer.valueOf( p_sStage[0] ); 
		this.gmRaceStageMenu2.iPage = Integer.valueOf( p_sStage[0] ); 
	}
	
	public void showRaceMenu() {
		switch ( this.gssStatus ) {
		case ghNormal:
			this.toTitle.sTxt = "Race";
			this.gmRaceMenu.showMenu();
			break;
		case ghRace:
			this.gmRaceMenu.hideMenu();
			break;
		default:
			break;
		}
	}
	
	public void showShopMenu() {
		switch ( this.gssStatus ) {
		case ghFeedGoShop:
			this.gmFeedGoShopMenu.hideMenu();
			this.gmFeedMenu.hideMenu();
		case ghNormal:
			this.toTitle.sTxt = "Shop";
			this.gmShopMenu.showMenu();
			break;
		case ghShop:
			this.gmShopMenu.hideMenu();
			break;
		default:
			break;
		}
	}
	
	public void showShopConfirmMenu( int itemId ) {
		switch ( this.gssStatus ) {
		case ghShop:
			goShopItemSelected.setAnimation(itemId-1);
			goShopItemSelected.playAnimation(true);
			this.buyItem = itemId;
			this.gmShopConfirmMenu.showMenu( false );
			break;
		case ghShopConfirm:
			this.gmShopConfirmMenu.hideMenu();
			break;
		default:
			break;
		}
	}
	
	public void showShopBuyErrMenu() {
		switch ( this.gssStatus ) {
		case ghShopConfirm:
			this.gmShopConfirmMenu.hideMenu();
			this.gmShopBuyErrMenu.showMenu( false );
			
			gpShopBuyErrMsg.setAnimation(this.buyItemErrCode);
			gpShopBuyErrMsg.playAnimation(true);
			break;
		case ghShopBuyErr:
			this.gmShopBuyErrMenu.hideMenu();
			break;
		default:
			break;
		}
	}
	
	public void showSettingMenu() {
		switch ( this.gssStatus ) {
		case ghNormal:
			this.toTitle.sTxt = "About";
			this.gmSettingMenu.showMenu();
			break;
		case ghSetting:
			this.gmSettingMenu.hideMenu();
			break;
		default:
			break;
		}
	}
	
	public void showCreditMenu() {
		switch ( this.gssStatus ) {
		case ghSetting:
			this.toTitle.iFontSize = 65;
			this.toTitle.sTxt = "About Game";
			this.gmCreditMenu.showMenu();
			break;
		case ghCredit:
			this.toTitle.sTxt = "About";
			this.gmCreditMenu.hideMenu();
			break;
		default:
			break;
		}
	}
	
	public void showSoundControlMenu() {
		switch ( this.gssStatus ) {
		case ghSetting:
			this.toTitle.iFontSize = 58;
			this.toTitle.sTxt = "Sound Control";
			this.gmSoundControlMenu.showMenu(); 
			break;
		case ghSoundControl:
			this.toTitle.sTxt = "Setting";
			this.gmSoundControlMenu.hideMenu();
			break;
		default:
			break;
		}
	}
	
	public void showTutorMenu() {
		switch ( this.gssStatus ) {
		case ghRace:
			this.toTitle.sTxt = "Tutorial";
			this.gmTutorMenu.showMenu();
			break;
		case ghTutor:
			this.gmTutorMenu.hideMenu();
			break;
		default:
			break;
		}
	}
	
	public void showFeedMenu() {
		switch ( this.gssStatus ) {
		case ghNormal:
			this.toTitle.sTxt = "Feed";
			this.gmFeedMenu.showMenu();
			break;
		case ghFeed:
			this.gmFeedMenu.hideMenu();
			break;
		default:
			break;
		}
	}
	
	public void showFeedConfirmMenu( int itemId ) {
		this.toTitle.sTxt = "Feed";
		
		switch ( this.gssStatus ) {
		case ghFeed:
			this.feedItem = itemId;
			if ( itemId == 1 && this.geMain.gpPref.getPerference( "gpItemOneQty" , 0 ) > 0 || itemId == 2 && this.geMain.gpPref.getPerference( "gpItemTwoQty" , 0 ) > 0 ) {
				this.gmFeedConfirmMenu.showMenu(false);
			}
			else {
				this.gmFeedGoShopMenu.showMenu(false);
			}
			break;
		case ghFeedConfirm:
			this.gmFeedConfirmMenu.hideMenu();
			break;
		case ghFeedGoShop:
			this.gmFeedGoShopMenu.hideMenu();
			break;
		default:
			break;
		}
	}
	
	public void showExitMenu() {
		switch ( this.gssStatus ) {
		case ghNormal:
			this.gmExitMenu.showMenu( false );
			break;
		case ghExit:
			this.gmExitMenu.hideMenu();
			break;
		default:
			break;
		}
	}
	
	public void showRaceStageMenu() {
		switch ( this.gssStatus ) {
		case ghRace:
		case ghMultiServerWait:
			this.gmRaceStageMenu.iPage = 0; 
			this.gmRaceStageMenu2.iPage = 0;
			this.gmRaceStageMenu.showMenu();
			this.gmRaceStageMenu2.showMenu( false );
			break;
			
		case ghRaceStage:
			this.toTitle.sTxt = "Race";
			this.gmRaceStageMenu2.hideMenu();
			this.gmRaceStageMenu.hideMenu();
			break;
		default:
			break;
		}
	}
	
	public void showMultiPlayMenu() {
		switch ( this.gssStatus ) {
		case ghMultiWait:
			this.bIsNetworkMode = true;
			this.sssStatus = StagSelectStatus.ServerSelecting;
			this.bIsAnyBTConnectionCreated = this.geMain.isAnyBTConnectionCreated();
			if ( this.geMain.gnhHandler.gnbtHandler.bIsServerSide ) {
				this.gmMultiServerWaitMenu.showMenu();
			}
			else {
				this.gmMultiClientWaitMenu.showMenu();
			}
			break;
		
		case ghMultiServerWait:
			this.gmMultiServerWaitMenu.hideMenu();
			this.showMultiWaitMenu();
			this.bIsNetworkMode = false;
			break;
			
		case ghMultiClientWait:
			this.gmMultiClientWaitMenu.hideMenu();
			this.showMultiWaitMenu();
			this.bIsNetworkMode = false;
			break;
			
		default:
			break;
		}
	}
	
	public void showMultiWaitMenu() {
		switch ( this.gssStatus ) {
		case ghRace:
			this.gmMultiWaitMenu.showMenu();
			
			this.geMain.showYesNoDialog(
				this.geMain.sPackageName
				,"Enable Multi-play mode?" 
				,new ButtonFunction() {
					@Override
					public String[] call() throws Exception {
						// TODO Auto-generated method stub
						geMain.gnhHandler.connBTByNFCInit( new ButtonFunction(){
							@Override
							public String[] call() throws Exception {
								showMultiPlayMenu();
								return null;
							}
						} );
						return null;
					}
				}
				,null
				,1);
			break;
		
		case ghMultiWait:
			// Disconnect
			this.geMain.gnhHandler.disconnect();
			this.gmMultiWaitMenu.hideMenu();
			break;
			
		default:
			break;
		}
	}
	
	public void bgSoundAdd() {
		this.statusBarBg.changeColor(  String.valueOf(1), 0);
		this.geMain.gmpPlayer.addVolume( GMPType.bgMusic , 20 );
		this.statusBarBg.setPlayerProgress( String.valueOf(1) , (float)this.geMain.gmpPlayer.getVolume( GMPType.bgMusic ) );
	}
	
	public void bgSoundMinus() {
		this.statusBarBg.changeColor(  String.valueOf(1), 0);
		this.geMain.gmpPlayer.addVolume( GMPType.bgMusic , -20 );
		this.statusBarBg.setPlayerProgress( String.valueOf(1) , (float)this.geMain.gmpPlayer.getVolume( GMPType.bgMusic ) );
	}
	
	public void bgSoundMuted() {
		this.geMain.gmpPlayer.mute( GMPType.bgMusic );
		
		if ( this.geMain.gmpPlayer.isMute( GMPType.bgMusic ) ) {
			this.btnBgSoundMuted.setAnimation(1);
			this.btnBgSoundMuted.playAnimation(true);
			this.statusBarBg.changeColor(  String.valueOf(1), 1);
		}
		else {
			this.btnBgSoundMuted.setAnimation(0);
			this.btnBgSoundMuted.playAnimation(true);
			this.statusBarBg.changeColor(  String.valueOf(1), 0);
		}
	}
	
	public void effectSoundAdd() {
		this.statusBarEffect.changeColor(  String.valueOf(1), 0);
		this.geMain.gmpPlayer.addVolume( GMPType.soundEffect , 20 );
		this.statusBarEffect.setPlayerProgress( String.valueOf(1) , (float)this.geMain.gmpPlayer.getVolume( GMPType.soundEffect ) );
	}
	
	public void effectSoundMinus() {
		this.statusBarEffect.changeColor(  String.valueOf(1), 0);
		this.geMain.gmpPlayer.addVolume( GMPType.soundEffect , -20 );
		this.statusBarEffect.setPlayerProgress( String.valueOf(1) , (float)this.geMain.gmpPlayer.getVolume( GMPType.soundEffect ) );
	}
	
	public void effectSoundMuted() {
		this.geMain.gmpPlayer.mute( GMPType.soundEffect );
		
		if ( this.geMain.gmpPlayer.isMute( GMPType.soundEffect ) ) {
			this.btnEffectSoundMuted.setAnimation(1);
			this.btnEffectSoundMuted.playAnimation(true);
			this.statusBarEffect.changeColor(  String.valueOf(1), 1);
		}
		else {
			this.btnEffectSoundMuted.setAnimation(0);
			this.btnEffectSoundMuted.playAnimation(true);
			this.statusBarEffect.changeColor(  String.valueOf(1), 0);
		}
	}
	
	@Override
	public void pushMsgPre() {
		JSONObject joMsg;
		
		try {
			if ( this.sssStatus == StagSelectStatus.ServerSelecting ) {
				if ( this.bIsAnyBTConnectionCreated ) {
					if ( this.geMain.gnhHandler.gnbtHandler.bIsServerSide ) {
						if ( this.iGoToStage != 0 ) {
							joMsg = new JSONObject().put( "RaceStage" , String.valueOf( this.iGoToStage ) );
							this.geMain.gnhHandler.gnbtHandler.pushMsg( joMsg );
							this.sssStatus = StagSelectStatus.ServerReady;
							this.sReadyMacAddr.clear();
						}
					}
					else {
						if ( this.iGoToStage != 0 ) {
							joMsg = new JSONObject().put( "RaceReady" , this.geMain.gnhHandler.gnbtHandler.getMacAddr() );
							this.geMain.gnhHandler.gnbtHandler.pushMsg( joMsg );
							this.sssStatus = StagSelectStatus.ClientReady;
						}
					}
				}
			}
		} catch ( Exception p_e ) {
			// TODO Auto-generated catch block
			GameUtil.LogMsg( this , "GameHome.pushMsgPre" );
			GameUtil.ErrorHandler( this , p_e );
		}
	}
	
	@Override
	public void readMsgPre() {
		String[] sLinkedMacAddr = null;
		String sMsg;
		JSONObject joMsg;
		
		try {
			if ( this.bIsAnyBTConnectionCreated ) {
				sLinkedMacAddr = this.geMain.gnhHandler.gnbtHandler.getLinkedMACAddr();
				for ( String btMACAddr : sLinkedMacAddr ) {
					sMsg = null;
					sMsg = this.geMain.gnhHandler.gnbtHandler.getMsg( btMACAddr );
					
					if ( sMsg != null && sMsg.length() > 0 ) {
						joMsg = new JSONObject( sMsg );
						
						if ( joMsg.has( "Disconnect" ) ) {
							this.geMain.gnhHandler.gnbtHandler.pollMsg( btMACAddr );
							this.geMain.gnhHandler.gnbtHandler.disconnect( joMsg.get( "Disconnect" ).toString() );
						}
						else {
							if ( this.geMain.gnhHandler.gnbtHandler.bIsServerSide ) {
								if ( joMsg.has( "RaceReady" ) && !this.sReadyMacAddr.contains( joMsg.get( "RaceReady" ).toString() ) ) {
									this.geMain.gnhHandler.gnbtHandler.pollMsg( btMACAddr );
									this.sReadyMacAddr.add( joMsg.get( "RaceReady" ).toString() );
								}
							}
							else {
								if ( joMsg.has( "RaceStage" ) ) {
									this.geMain.gnhHandler.gnbtHandler.pollMsg();
									this.iGoToStage = Integer.valueOf(joMsg.get( "RaceStage" ).toString());
								}
							}
						}
					}
				}
				
				if ( this.geMain.gnhHandler.gnbtHandler.bIsServerSide ) {
					if ( sLinkedMacAddr != null ) {
						if ( this.sReadyMacAddr.size() == sLinkedMacAddr.length ) {
							this.sssStatus = StagSelectStatus.AllReady;
						}
					}
				}
			}
		} catch ( Exception p_e ) {
			// TODO Auto-generated catch block
			GameUtil.LogMsg( this , "GameHome.readMsgPre" );
			GameUtil.ErrorHandler( this , p_e );
		}
	}
	
	@Override
	public void pushMsgPost() {
		try {
			if ( this.bIsAnyBTConnectionCreated ) {
				if ( this.geMain.gnhHandler.gnbtHandler.bIsServerSide ) {
					if ( this.sssStatus == StagSelectStatus.AllReady ) {
						this.geMain.gnhHandler.gnbtHandler.pushMsg( new JSONObject().put( "RaceStart" , "true" ) );
					}
				}
			}
		} catch ( Exception p_e ) {
			// TODO Auto-generated catch block
			GameUtil.LogMsg( this , "GameHome.pushMsgPost" );
			GameUtil.ErrorHandler( this , p_e );
		}
	}
	
	@Override
	public void readMsgPost() {
		try {
			if ( this.bIsAnyBTConnectionCreated ) {
				if ( !this.geMain.gnhHandler.gnbtHandler.bIsServerSide ) {
					String sMsg = this.geMain.gnhHandler.gnbtHandler.getMsg();
					
					if ( sMsg != null && sMsg.length() > 0 ) {
						JSONObject joMsg = new JSONObject( sMsg );
						if ( joMsg.has( "RaceStart" ) && joMsg.get( "RaceStart" ).toString().equals("true") ) {
							this.geMain.gnhHandler.gnbtHandler.pollMsg();
							this.sssStatus = StagSelectStatus.AllReady;
						}
					}
				}
			}
		} catch ( Exception p_e ) {
			// TODO Auto-generated catch block
			GameUtil.LogMsg( this , "GameHome.readMsgPost" );
			GameUtil.ErrorHandler( this , p_e );
		}
	}
	
	@Override
	public void preGameLoopLogic() {
		if ( this.sssStatus == StagSelectStatus.AllReady && this.iGoToStage != 0 ) {
			this.goRacePage( new String[]{ String.valueOf( this.iGoToStage ) } );
		}
		
		super.preGameLoopLogic();
	}
}
